import 'package:flutter/material.dart';
import 'package:shopping_group/main/lz_mall/model/lz_mall_category_model.dart';
import 'package:shopping_group/main/lz_mall/model/lz_mall_category_prduct_model.dart';

class LzMallHomeProvider extends ChangeNotifier {
  //数据源
  List<LzMallCategoryModel> categoryModels = [];

  //当前分类
  LzMallCategoryModel currentCategoryModels;

  //当前子分类
  LzMallCategoryModel currentSubCategoryModels = LzMallCategoryModel();

  Map<String, List<LzCategoryProductModel>> dataMap = {};

  //数据源
  List<LzCategoryProductModel> productModel = [];

  //分类的数据
  setCategoryModels(value) {
    categoryModels = value;
    notifyListeners();
  }

  //保存一下数据源
  setDataMap(Map<String, List<LzCategoryProductModel>> data) {
    if (productModel == null) productModel = [];
    productModel.clear();
    productModel.addAll(data.values.first);
    dataMap.addAll(data);
    notifyListeners();
  }

  //分类的数据
  setCurrentCategoryModels(LzMallCategoryModel value) {
    currentCategoryModels = value;
    productModel = dataMap[value.id];
    notifyListeners();
  }

  //分类子分类的数据
  setCurrentSubCategoryModels(LzMallCategoryModel value) {
    currentSubCategoryModels = value;
    productModel = dataMap[value.id] ?? [];
    notifyListeners();
  }
}
